import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    meta: {
      title: "会员管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/member',
        name: 'member',
        component: () => import('@/views/member/index.vue'),
        meta: {
          title: "会员管理",
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-tools',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
      {
        path: 'policy',
        name: 'policy',
        component: () => import('@/views/system/policy/index.vue'),
        meta: {
          title: "政策管理",
        }
      },
    ]
  },
  {
    path: '/idle',
    component: Layout,
    meta: {
      title: "闲置物资设备",
      icon: 'el-icon-goods',
    },
    name: 'idle',
    children: [
      {
        path: 'category',
        name: 'idleCategory',
        component: () => import('@/views/idle/category/index.vue'),
        meta: {
          title: "分类管理",
        }
      },
      {
        path: 'item',
        name: 'idleItem',
        component: () => import('@/views/idle/item/index.vue'),
        meta: {
          title: "物资/设备管理",
        }
      },
      {
        path: 'transfer',
        name: 'idleTransfer',
        component: () => import('@/views/idle/transfer/index.vue'),
        meta: {
          title: "调拨管理",
        }
      },
      {
        path: 'statistics',
        name: 'idleStatistics',
        component: () => import('@/views/idle/statistics/index.vue'),
        meta: {
          title: "统计分析",
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
